<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax读取json文件</title>
    <script src="./jquery-1.8.0.js"></script>
</head>
<body>
  <span>Ajax读取json文件[<a href="./1.json">1.json</a>]：</span>
  <span class="box"></span>
    <script>
        $(document).ready(function(){
            $.ajax({
                type: "get",//请求类型
                datatype: "json",//数据类型
                //url: "http://localhost:8080/D:/HTML20220924/%E6%A1%88%E4%BE%8B1/HTML1/demo.json",//向哪里请求
                url: "./1.json",//向哪里请求
                success: function(data){//请求成功后执行该函数
                    console.log(data.name)
                    document.querySelector(".box").innerHTML=data.name
                }
            })
        })
    </script>
</body>
</html>
